--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';

--CREATE TABLE se_CPT_TPFART AS (SELECT * FROM &erp.CPT_TPFART WHERE 1=2);




DELETE FROM se_CPT_TPFART;

 INSERT INTO se_CPT_TPFART
 (SELECT id tpfart_cod,
         0 enreg_id,
         'N' enreg_s,
         libelle tpfart_lib,
         NULL tpfart_lib2,
         'T' tiers_typ,
         NULL taxedi_cod
    FROM uv_ctpf) ;



 UPDATE se_CPT_TPFART tf SET enreg_id=(select enreg_id FROM &erp.CPT_TPFART f WHERE f.tpfart_cod=tf.tpfart_cod) ;
 UPDATE se_CPT_TPFART tf SET enreg_id=&outils.enreg_id.NEXtvaL WHERE enreg_id IS NULL OR enreg_id =0;



 CALL uvse_synchroverserp('tpfart_cod','CPT_TPFART','O') ;

 commit;



select * from (
SELECT &outils.stragg(source) source, tpfart_cod, enreg_id, enreg_s, tpfart_lib, tpfart_lib2, tiers_typ ,taxedi_cod
FROM (
  SELECT 'uv' source ,g.* FROM se_CPT_TPFART g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.CPT_TPFART g
  )
GROUP BY  tpfart_cod, enreg_id, enreg_s, tpfart_lib, tpfart_lib2, tiers_typ ,taxedi_cod
HAVING Count(1)!=2) r
ORDER BY tpfart_cod;